<?php

$mtypearr=array(""=>"选择食材类型",1=>"易保存食材",2=>"不易保存食材(需当天采购)");
$operatelist=array(
"100"=>"创建加工单",
"101"=>"加工单领料",
"102"=>"加工完成",
"103"=>"补领",
"104"=>"取消加工单",
"110"=>"提交质检",
"114"=>"质检退回",
"112"=>"质检完成",
"113"=>"质检部分完成",
"115"=>"标签打印",
"116"=>"成品部分入库",
"117"=>"成品全部入库",
);

$metcatlist=array(
""=>"选择分类",
"1"=>"肉类",
"2"=>"水产",
"3"=>"家禽",
"4"=>"海鲜",
"5"=>"蛋类",
"6"=>"蔬菜",
"7"=>"干货",
"8"=>"豆制品",
"12"=>"调料"
);

function encrypt($data, $key) { 
$prep_code = serialize($data); 
$block = mcrypt_get_block_size('des', 'ecb'); 
if (($pad = $block - (strlen($prep_code) % $block)) < $block) { 
$prep_code .= str_repeat(chr($pad), $pad); 
} 
$encrypt = mcrypt_encrypt(MCRYPT_DES, $key, $prep_code, MCRYPT_MODE_ECB); 
return base64_encode($encrypt); 
} 

function decrypt($str, $key) { 
$str = base64_decode($str); 
$str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB); 
$block = mcrypt_get_block_size('des', 'ecb'); 
$pad = ord($str[($len = strlen($str)) - 1]); 
if ($pad && $pad < $block && preg_match('/' . chr($pad) . '{' . $pad . '}$/', $str)) { 
$str = substr($str, 0, strlen($str) - $pad); 
} 
return unserialize($str); 
} 


function getIpPlace($ip){  
   require_once("IpLocation.php");
   $ipfile = EZROOT."/data/qqwry.dat";  
   $iplocation = new IpLocation($ipfile); 
   $ipresult = $iplocation->getlocation($ip);  
   return $ipresult["country"];  
}
function showIp($ip){  
    if(empty($ip)){
        return '';
    }
    $list=explode(".",$ip);
    
    return $list[0].".".$list[1].".".$list[2].".*";
}


function ez_file_put($file,$data,$mode=FILE_USE_INCLUDE_PATH){
	return file_put_contents($file,$data,$mode);
}
function seed() 
{
	list ( $msec, $sec ) = explode ( ' ', microtime () );
	return ( float ) $sec;
}
function parse_raw_url($raw_url) {
		$retval = array ();
		$raw_url = (string) $raw_url;

		// make sure parse_url() recognizes the URL correctly.
		if (strpos($raw_url, '://') === false) {
			$raw_url = 'http://' . $raw_url;
		}

		// split request into array
		$retval = parse_url($raw_url);

		// make sure a path key exists
		if (!isset ($retval['path'])) {
			$retval['path'] = '/';
		}

		// set port to 80 if none exists
		if (!isset ($retval['port'])) {
			$retval['port'] = '80';
		}

		return $retval;
}
function curl($url, $method = 'get') {
		$urlinfo = parse_url($url);
	    if (empty ($urlinfo['path'])) {
		    $urlinfo['path'] = '/';
	    }
	    $host = $urlinfo['host'];
		if(!array_key_exists('query',$urlinfo)){
		    $urlinfo['query']='';
		}
	    $uri = $urlinfo['path'] . $urlinfo['query']; 
		
		/* 开始一个新会话 */
		$curl_session = curl_init();

		/* 基本设置 */
		curl_setopt($curl_session, CURLOPT_FORBID_REUSE, true); // 处理完后，关闭连接，释放资源
		curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true); //把结果返回，而非直接输出
		curl_setopt($curl_session, CURLOPT_FOLLOWLOCATION,1);  //是否抓取跳转后的页面
		curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, 20); //超时时间

		if(preg_match('|^https://|',$url)==1){
		    curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl_session, CURLOPT_SSL_VERIFYHOST,  false);
		}

		$url_parts = parse_raw_url($url);

		if ($method == 'get') {
			$header[]= "GET " . $urlinfo['path'] . "?" . $urlinfo['query'] . " HTTP/1.1\r\n";
	    	$header[]= "Host: " . $urlinfo['host'] . "\r\n";
			curl_setopt($curl_session, CURLOPT_HTTPGET, true);
		} else {
			$a = explode('?', $url);
			$url = $a[0];
			$params = $a[1];
			curl_setopt($curl_session, CURLOPT_POST, true);
			curl_setopt($curl_session, CURLOPT_POSTFIELDS, $params);

		}

		curl_setopt($curl_session, CURLOPT_URL, $url);
		


		$http_response = curl_exec($curl_session);
		curl_close($curl_session);
		return $http_response;
}
    

function make_avatar_path($uid, $dir = '.') {
        $uid = sprintf("%010d", $uid);
        $dir1 = substr($uid, 0, 4);
        $dir2 = substr($uid, 4, 4);
        !is_dir($dir.'/'.$dir1) && mkdir($dir.'/'.$dir1, 0777);
        !is_dir($dir.'/'.$dir1.'/'.$dir2) && mkdir($dir.'/'.$dir1.'/'.$dir2, 0777);
	return $dir.'/'.$dir1.'/'.$dir2.'/';
}
    
function show_result_msg($data,$md5string){
    global $ResMsg;
    $msgno=$data["respcode"];
    $data["resmsg"]=$ResMsg[$msgno];
    $data["signature"]=md5($md5string);
    reset($data);
    $newdata=array();
    while(list($k,$v)=each($data)){
       
        if(is_null($v)){
            $v="";
        }        
        if(is_array($v)){
            $newv=array();
            while(list($k2,$v2)=each($v)){
                if(is_null($v2)){
                    $v2="";
                }                  
                 $newv[$k2]=$v2;   
           }
           $v=$newv;     
        }

        $newdata[$k]=$v;
    }
    ob_start();
    $str = json_encode($newdata);
    echo $str;
    $len = strlen(ob_get_contents());
    header('Content-type: text/html;charset=utf-8');
    header("Content-Length: " . $len);
    ob_flush();
    exit;
}
/*数组相关函数*/
function logout_key($a, $b) {
	foreach ($b as $v) {
		unset ($a[$v]);
	}
	return $a;
}

function make_user_seed()
{
  global $ezhand;
  list($usec, $sec) = explode(' ', microtime());
  $rt=(float) $sec + ((float) $usec * 100000);
  srand($rt);
  $randval = date("s").rand(10000000,99999999);
  $Row=$ezhand->select('user','id','ddusername='.$randval);
  if(!empty($Row)){
    list($usec, $sec) = explode(' ', microtime());
    $rt=(float) $sec + ((float) $usec * 100000);
    srand($rt);    
    $randval = date("s").rand(10000000,99999999);
  }
  
  return $randval;
}
function random_string($length, $max=FALSE)
{
  if (is_int($max) && $max > $length)
  {
    $length = mt_rand($length, $max);
  }
  $output = '';
  for ($i=0; $i<$length; $i++)
  {
    $which = mt_rand(0,2);
    if ($which === 0)
    {
      $output .= mt_rand(0,9);
    }
    elseif ($which === 1)
    {
      $output .= chr(mt_rand(65,90));
    }
    else
    {
      $output .= chr(mt_rand(97,122));
    }
  }
  return $output;
}


function gen_token() {
          $token = md5(uniqid(rand().time(), true));
          return $token;
}
function gen_stoken() {
  session_start();
  $_SESSION["WSTOKEN_NAME"] = gen_token();

}

     
function arr_diff($arr1, $arr, $xs = 1) { //xs=0，arr是键值  xs=1，arr是键名
	if ($xs == 1) {
		foreach ($arr as $k => $v) {
		    $arr1[$v] = '%$%^@#$asdsfsdf355432';
		}
		$arr3 = array_diff($arr1, array('%$%^@#$asdsfsdf355432'));
	} 
	else {
		$arr3 = array_diff($arr1, $arr);
	}
	return $arr3;
}

function empty2zero(&$arr,$keyarr){ //指定键值空转0
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            //empty2zero($arr[$key]);
            $arr[$key]=serialize($value);
        } else {
            $value = trim($value);
            if ($value == '' and in_array($key,$keyarr)) {
                $arr[$key] = 0;
            }
        }
    }
}

function arr2param($arr){
	$param='';
    foreach($arr as $k=>$v){
		$param.='&'.$k.'='.rawurlencode($v);
	}
	return $param;
}

function diguiFilter(&$p, $ArrFiltrate,$c) {
	for ($i=0;$i<$c;$i++) {
		$sql = $ArrFiltrate[$i];
		if (strpos(strtolower($p), $sql)!==false) {
			$p = preg_replace('#' . $sql . '#i', '', $p);
			diguiFilter($p, $ArrFiltrate,$c);
		} else {
			if($i==$c-1){return false;}
		}
	}
}

function filter(&$array,$ArrFiltrate,$c=0)
{
	if($c==0){
		$c=count($ArrFiltrate);
	}
	if (is_array($array))
	{
		foreach ($array as $key => $value)
		{
			if (is_array($value))
				filter($array[$key],$ArrFiltrate,$c);
			else
				diguiFilter($array[$key], $ArrFiltrate,$c);
		}
	}
}

function arr_replace($arr,$key,$val){
    $arr[$key]=$val;
	return $arr;
}

function arr_get_key($arr,$v){
	foreach($arr as $key=>$val){
	    if($v==$val){
			return $key;
		}
	}
}


function trim_arr(&$arr){
	if (is_array($arr)) {
		foreach($arr as $k=>$v){
			if (is_array($v)) {
				 trim_arr($v);
			}
			else{
				$arr[$k]=trim($v);
			}
		}
	}
	else{
		$arr=trim($arr);
	}
}

function back_arr($a) {  //倒叙数组
	$c = count($a);
	$d = $c;
	$b = array ();
	$m = 0;

	for ($i = 0; $i < $d; $i++) {
		$c = count($a);
		foreach ($a as $k => $v) {
			$m++;
			if ($m == $c) {
				$b[$k] = $v;
				$m = 0;
				unset ($a[$k]);
			}
		}
	}
	return $b;
}

function arr2canshu($array){
	$b='';
	foreach($array as $v){
		$b.='ids%5B%5D='.$v.'&';
	}
	return preg_replace('/&$/','',$b);
}

/*html相关函数*/
function select($array, $id = 10000, $name,$attr='',$return=0) {
	$i = 0;
	$s = '<select name="'.$name.'" id="'.$name.'" class="'.$name.'" '.$attr.'>';
	foreach ($array as $key => $val) {
		if ($id == $key && isset($id)){
		    $select = 'selected';
		}
		else{
			$select = '';
		}
		$s.= "<option value='$key' $select style='background:$bg'>$val</option>";
		$i++;
	}
	$s.= "</select>";
	if($return==1){
		return $s;
	}
	else{
		echo $s;
	}
}
function select_copy($fields,$array, $id = 10000, $name,$attr='',$return=0) {
	$i = 0;
	$s = '<select name="'.$name.'" id="'.$name.'" class="'.$name.'" '.$attr.'>';
	foreach ($array as $key => $val) {
		if ($id == $key && isset($id)){
		    $select = 'selected';
		}
		else{
			$select = '';
		}
		$s.= "<option value='$key' $select style='background:$bg'>$val[$fields]</option>";
		$i++;
	}
	$s.= "</select>";
	if($return==1){
		return $s;
	}
	else{
		echo $s;
	}
}
function html_check($array,$id,$name){

    if(!empty($id)){
        $idlist=unserialize($id);
    }else{
        $idlist=array();
    }
    foreach ($array as $key => $val) {
        if(is_array($val)){
            $val=$val["title"];
            
        }
		if (in_array($key,$idlist))
			$checked = 'checked="checked"';
		else
			$checked = '';
		echo "<label><input ".$checked." name='".$name."[]' type='checkbox' value='".$key."' /> ".$val."</label>&nbsp;&nbsp;";
	}    
    
}
function html_radio($array,$id,$name){
    foreach ($array as $key => $val) {
		if ($id == $key)
			$checked = 'checked="checked"';
		else
			$checked = '';
		echo "<input ".$checked." name='".$name."' type='radio' value='".$key."' /> ".$val."&nbsp;&nbsp;";
	}
}

function html_img($pic_url,$type='',$alt='',$class='',$width='',$height='',$onerror_pic=''){ //type大于10为不给图片进行js加密，类型再去个位数
	if($onerror_pic==''){
		$onerror_pic=SITEURL.'/images/dian.png';
	}
	if($type>=10){$img_type=$type%10;}
	else{$img_type=$type;}
	switch($img_type){
	    case 1:
		    $pic_url=$pic_url."_100x100.jpg";
		break;
		case 2:
		    $pic_url=$pic_url."_b.jpg";
		break;
		case 3:
		    $pic_url=$pic_url."_310x310.jpg";
		break;
		case 5:
		    $pic_url=$pic_url;
		break;        
	}
	$pic_url=base64_encode($pic_url);
	if($type>=10){
		if($alt!=''){$alt='alt="'.$alt.'"';}
	    if($class!=''){$class='class="'.$class.'"';}
	    if($width>0){$width='width:'.$width.'px';}else{$width='';}
	    if($height>0){$height=';height:'.$height.'px';}else{$height='';}
		$onerror='onerror="this.src=\''.$onerror_pic.'\'"';
		$re= "<img src='".base64_decode($pic_url)."' ".$alt." ".$class." style='".$width." ".$height."' ".$onerror."/>";
	}
	elseif(PICJM==0){
		if(strpos($alt,"'")!==false){
			$alt=str_replace("'",'',$alt);
		}
		
	    $re= "<SCRIPT language=javascript>setPic('".$pic_url."','".$width."','".$height."','".$alt."','".$class."','".$onerror_pic."');</SCRIPT>";
	}
	elseif(PICJM==1){
		$pic_url=urlencode($pic_url);
	    if($alt!=''){$alt='alt="'.$alt.'"';}
	    if($class!=''){$class='class="'.$class.'"';}
	    if($width>0){$width='width:'.$width.'px';}else{$width='';}
	    if($height>0){$height=';height:'.$height.'px';}else{$height='';}
		$onerror='onerror="this.src=\''.$onerror_pic.'\'"';
		if(PICWJT==0){
		    $re= "<img src='".SITEURL."/comm/showpic.php?pic=".$pic_url."' ".$alt." ".$class." style='".$width." ".$height."' ".$onerror."/>";
		}
	    else{
		    $re= "<img src='".SITEURL."/tbimg/".$pic_url.".jpg' ".$alt." ".$class." style='".$width." ".$height."' ".$onerror."/>";
		}
	}
	return $re;
}

function script($str){
    return '<script language="javascript" type="text/javascript">'.$str.'</script>';
}



function qq($qq,$type=1){
	switch($type){
		case 1:
			return '<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin='.$qq.'&site=qq&menu=yes"><img style="height:16px" border="0" src="http://wpa.qq.com/pa?p=2:'.$qq.':46" alt="点击这里给我发消息" title="点击这里给我发消息"></a>';
		break;
		case 2:
			return '<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin='.$qq.'&site=qq&menu=yes"><img style="width:21px; height:21px" border="0" src="http://wpa.qq.com/pa?p=2:'.$qq.':45" alt="点击这里给我发消息" title="点击这里给我发消息"></a>';
		break;
	}
    
}

function a($uid, $size = '', $type = '') {
	$size = in_array($size, array (
		'big',
		'middle',
		'small'
	)) ? $size : 'middle';
	$uid = abs(intval($uid));
	$uid = sprintf("%010d", $uid);
	$dir1 = substr($uid, 0, 4);
	$dir2 = substr($uid, 4, 4);
	//$dir3 = substr($uid, 5, 2);
	$typeadd = $type == 'real' ? '_real' : '';
	$avatar_path=SITEURL.'/upload/avatar/'.$dir1 . '/' . $dir2 . '/' . substr($uid, -2) . $typeadd . "_avatar_$size.jpg";
	if(file_exists(EZROOT.'/'.$avatar_path)) return $avatar_path;
	else return SITEURL.'/upload/noavatar_'.$size.'.jpg';
}



function limit_input($name,$value=DEFAULTPWD,$width='150',$pwd=1){
    if(strpos($name,'[')!==false){
	    preg_match('/\[(.*)\]/',$name,$a);
		$b=str_replace('['.$a[1].']','',$name);
		$id=$b.$a[1];
	}
	else{
	    $id=$name;
	}
	if($pwd==1){
	    $type='password';
	}
	else{
	    $type='text';
	}
	return $s='<input style="width:'.$width.'px" type="'.$type.'" name="'.$name.'" id="'.$id.'" readonly="readonly" class="disabled" value="'.$value.'"/><input type="checkbox" title="激活修改" onClick="if($(this).attr(\'checked\')==true){$(\'#'.$id.'\').attr(\'readonly\',\'\').removeClass(\'disabled\');}else{$(\'#'.$id.'\').attr(\'readonly\',\'readonly\').addClass(\'disabled\');}"  />';
}


/*文件操作相关函数*/
function make_arr_cache($arr, $name,$root=0) {
	$data = "<?php\n return " . var_export($arr, true) . ";\n?>";
	if($root==0){
	    ez_file_put(EZROOT .'/' . $name . '.php', $data);
	}
	else{
	    ez_file_put($name . '.php', $data);
	}
}

function create_dir($dir) {
	if ($dir!='/' && !is_dir($dir)) {
		$d=str_replace(EZROOT.'/','',$dir);
		$d_arr=explode('/',$d);
		$di='';
		foreach($d_arr as $v){
			$di.='/'.$v;
			if(is_dir(EZROOT.$di)){
				if(iswriteable(EZROOT.$di)==0){
					return $di.'目录不可写';
				}
			}
			else{
				mkdir(EZROOT.$di);
			}
		}
	}
}

function create_file($file,$data='',$add=0,$detect=1,$original=0){
	$file=str_replace("\\", '/', $file);
    if($detect==1){
		$dir_arr=explode('/',$file);
	    $c=count($dir_arr);
		unset($dir_arr[$c-1]);
		$dir=implode('/',$dir_arr);
		create_dir($dir);
	}
	if($add==0){
		if($original==0){
			return ez_file_put($file,$data);
		}
		else{
			return file_put_contents($file,$data);
		}
	}
	else{
		return ez_file_put($file,$data,FILE_APPEND);
	}
}

function iswriteable($file){
	if(!file_exists($file)){
		return 0;
	}
	$writeable = 0;
    if(is_dir($file)){  
	    $dir=$file;  
		file_put_contents($dir.'/test.txt',1);
		if(file_exists($dir.'/test.txt')){
			if(unlink($dir.'/test.txt')){
				$writeable = 1; 
			}
		}
	}
	else{  
		if(file_exists($file)){
			$rename=rename($file,$file.'.ez');
			if($rename==1){
				rename($file.'.ez',$file);
			}
			file_put_contents($file,'ez_test_file_exists',FILE_APPEND);
			$a=file_get_contents($file);
			if(preg_match('/ez_test_file_exists$/',$a)){
				$a=preg_replace('/ez_test_file_exists$/','',$a);
				if(file_put_contents($file,$a)>0){
					$update = 1;
				}
			}
		}
		$writeable=$rename*$update;
	} 
	return $writeable;
}

function directory_size($directory) {
	$directorySize = 0;
	if(!file_exists($directory)){return 0;}
	if ($dh =  opendir($directory)) {
		while (($filename = readdir($dh))) {
			if ($filename != "." && $filename != "..") {
				if (is_file($directory . "/" . $filename))
					$directorySize += filesize($directory . "/" . $filename);
				if (is_dir($directory . "/" . $filename))
					$directorySize += directory_size($directory . "/" . $filename);
			}
		} 
	} 
    closedir($dh);
	return $directorySize;
}

function deldir($dir) {
	if (!file_exists($dir)) {
		return false;
	} 
	if($dh = opendir($dir)){
		while ($file = readdir($dh)) {
			if ($file != "." && $file != "..") {
				$fullpath = $dir . "/" . $file;
				if (!is_dir($fullpath)) {
					unlink($fullpath);
				} else {
					deldir($fullpath);
				}
			}
		}
	closedir($dh);
	}
	if (rmdir($dir)) {
		return true;
	} else {
		return false;
	} 
}

function MkdirAll($truepath) {
	if (!file_exists($truepath)) {
		mkdir($truepath, 0777);
		chmod($truepath, 0777);
		return true;
	} else {
		return true;
	}
}

function judge_empty_dir($directory){      
    $handle = opendir($directory);      
    while (($file = readdir($handle)) !== false){          
        if ($file != "." && $file != ".."){              
            closedir($handle);              
            return 0;          
        }      
    }     
    closedir($handle);     
    return 1;  
}


/*文字字符串相关函数*/
function utf_substr($str, $len,$end="...") {
	for ($i = 0; $i < $len; $i++) {
		$temp_str = substr($str, 0, 1);
		if (ord($temp_str) > 127) {
			$i++;
			if ($i < $len) {
				$new_str[] = substr($str, 0, 3);
				$str = substr($str, 3);
			}
		} else {
			$new_str[] = substr($str, 0, 1);
			$str = substr($str, 1);
		}
	}
    
    if(strlen($str)<=len){
        $end="";
    }
	return join($new_str).$end;
}

function str_del_last($str){
	$newstr = substr($str,0,strlen($str)-1);
	return $newstr;
}

/*验证相关函数*/
function reg_name($name,$min=3,$max=15,$shield_arr=array()){
	if($name=='网站客服'){
		return -2; //包含非法词汇
	}
	$strl=str_utf8_chinese_word_count($name)*2+str_utf8_english_count($name);
	if($strl<$min or $strl>$max){
	    return -1; //用户名不合法
	}
	if(!empty($shield_arr)){
	    foreach($shield_arr as $v=>$k){
	        if(strpos($name,$v)!==false){
			    return -2; //包含非法词汇
	        }
	    }
	}
	$pcre_name = "/^[a-zA-Z0-9_\.\-@\x80-\xff]+$/"; //utf-8
	//$pcre_name = "/^[a-z0-9_".chr(0xa1)."-".chr(0xff)."]+$/"; //gbk
    if(preg_match($pcre_name,$name)){
        return 1;
    }else{
        return -1;  //用户名不合法
    }
}

function reg_password($pwd){
	$pcre_pwd = '/.{6,20}/';
    if(preg_match($pcre_pwd,$pwd)){
        return 1;
    }else{
        return 0;
    }
}

function reg_email($email){
	$pcre_email = '/^[-0-9a-zA-Z_.]+@([0-9a-zA-Z][_\-0-9a-zA-Z.]{0,30}\.)[a-zA-Z]{2,10}$/';
    if(preg_match($pcre_email,$email)){
        return 1;
    }else{
        return 0;
    }
}

function reg_qq($qq){
	$pcre_qq = '/^[0-9]{4,20}$/';
    if(preg_match($pcre_qq,$qq) || reg_email($qq)==1){
        return 1;
    }else{
        return 0;
    }
}

function reg_mobile($mobile){
	$pcre_mobile = '/^1[0-9]{10}$/';
    if(preg_match($pcre_mobile,$mobile)){
        return 1;
    }else{
        return 0;
    }
}

function is_url($url){
	$pcre_url = '/^http:\/\/[\w-]+\.[\w-]+[\.[\w-]|]+[\/=\?%\-&~`@[\]\':+!\w]+$/';
    if(preg_match($pcre_url,$url)){
        return 1;
    }else{
        return 0;
    }
}

function reg_taobao_url($url){
    if(preg_match('/(taobao\.com|tmall\.com)/',$url)==1){
		return 1;
	}
	else{
	    return 0;
	}
}

function reg_alipay($alipay){
	$is_email=reg_email($alipay);
	if($is_email==1){
	    return 1;
	}
	else{
		$is_mobile=reg_mobile($alipay);
	    if($is_mobile==1){
		    return 1;
		}
		else{
		    return 0;
		}
	}
}

function reg_tenpay($tenpay){
	$is_email=reg_email($tenpay);
	if($is_email==1){
		return 1;
	}
	$is_qq=reg_qq($tenpay);
	if($is_qq==1){
		return 1;
	}
	$is_mobile=reg_mobile($tenpay);
	if($is_mobile==1){
		return 1;
	}
	return 0;
}

function reg_bank_code($code){
	$len=strlen($code);
	if(is_numeric($code) && $len>=16 && $len<=19){
		return 1;
	}
	else{
		return 0;
	}
}

function reg_time($time){
	if($time==''){return 0;}
    $unixTime = strtotime($time);
    if (!is_numeric($unixTime)){
		return 0;
	}
	return 1;
}

function reg_captcha($yzm,$code='captcha'){
	if($yzm==''){return 0;}
	else{$yzm=strtolower($yzm);}
    if(!defined('ADMIN')){
		session_start();
	}
    
	$captcha=strtolower($_SESSION[$code]);
	unset($_SESSION[$code]);
	if($captcha=='' || $yzm!=$captcha){
	    return 0;
	}
	return 1;
}

function ez_encrypt($val,$key){
    return base64_encode($key.$val);
}

function ez_decrypt($val,$key){
	$a=base64_decode($val);
    $a=preg_replace('/^'.$key.'/','',$a);
	return $a;
}

function fs($class)
{
	if(!class_exists($class)){include(EZROOT.'/libs/'.$class.'.class.php');}
	static $classes = array();
	if(!isset($classes[$class]) || $classes[$class] === NULL)
	{
		$classes[$class] = new $class();
		//unset($class);
	}
	return $classes[$class];
}

function compact_html($str) {
	$str = preg_replace("/\t/", "", $str);
	$str = preg_replace("/\r\n/", "", $str);
	$str = preg_replace("/\r/", "", $str);
	$str = preg_replace("/\n/", "", $str);
	$str = preg_replace("/\s/", "", $str);
	return $str;
}

function get_final_url($url) {
	$str = '';
	$url = parse_url($url);
	$fp = fsockopen($url['host'], 80, $errno, $errstr);
	if ($fp) {
		if (!array_key_exists('query', $url)) {
			$url['query'] = '';
		}

		$header = "GET " . $url['path'] . "?" . $url['query'] . " HTTP/1.1\r\n";
		$header .= "Host: " . $url['host'] . "\r\n";
		$header .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1\r\n";
		$header .= "Referer: http://" . $url['host'] . "\r\n";
		$header .= "Connection: Close\r\n\r\n";
		fwrite($fp, $header);
		while (!feof($fp)) {
			$s = fgets($fp, 128);
			$str .= $s;
		}
		fclose($fp);
		preg_match("|Location:(.*?)Content-Type|", compact_html($str), $arr);
		return $arr[1];
	}
}

function dsetcookie($var, $value = '', $life = 0,$cookie_path='/',$cookie_domain=SURL,  $http_only = false)
{
	$_COOKIE[$var] = $value;

	if($value == '' || $life < 0)
	{
		$value = '';
		$life = -1;
	}

	$life = $life > 0 ? TIME + $life : ($life < 0 ? TIME - 31536000 : 0);
	$path = $http_only && PHP_VERSION < '5.2.0' ? $cookie_path.'; HttpOnly' : $cookie_path;

	$secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
	if(PHP_VERSION < '5.2.0')
	{
		setcookie($var, $value, $life, $path, $cookie_domain, $secure);
	}
	else
	{
		setcookie($var, $value, $life, $path, $cookie_domain, $secure, $http_only);
	}
}

function set_cookie($var, $value = '', $life = 1200,$encrypt=1){
	if($encrypt==1 && $life!=0){
	    $value=authcode($value, 'ENCODE');
	}
	
	if($life>0 && $value!=''){
		$life=TIME+$life;
	}
	else{
		$life=TIME-3153600000;
		$value='';
	}
	$_COOKIE[$var] = $value;
	setcookie($var, $value, $life,'/');
}

function get_cookie($var,$encrypt=1){
	if(isset($_COOKIE[$var])){
	    if($encrypt==1){
	       $value=authcode($_COOKIE[$var], 'DECODE');
	    }
        else{
	        $value=$_COOKIE[$var];
	    }
	    return $value;
	}
	else{
	    return '';
	}
}

function user_login($uid,$md5pwd,$life=''){
	if($life==''){$life=3600*24;}
	$userlogininfo=serialize(array('uid'=>$uid,'ezusername'=>$md5pwd,'ezsavetime'=>$life));
	$_SESSION["UserLoginInfo"]=$userlogininfo;
    set_cookie("userlogininfo", $userlogininfo, $life);
    
}

function webtype($a,$b=''){
    if(WEBTYPE==0){
	    return $a;
	}
	else{
	    return $b;
	}
}

function extension($filename){  //求后缀名
	if(strpos($filename,'/')!==false){
		$arr= explode('/',$filename);
		$arr = array_reverse($arr);
		if(strpos($arr[0],'.')!==false){
			$row= explode('.',$arr[0]);
			$row = array_reverse($row);
			return $row[0];
		}
		else{
			return '';
		}
	}
	else{
		if(strpos($filename,'.')!==false){
			$row = array_reverse($row);
			return $row[0];
		}
		else{
			return '';
		}
	}
}


function get_client_ip() {
	$ip = $_SERVER['REMOTE_ADDR'];
	if (isset($_SERVER['HTTP_X_REAL_FORWARDED_FOR']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_REAL_FORWARDED_FOR'])) {
		$ip = $_SERVER['HTTP_X_REAL_FORWARDED_FOR'];
	}  
    elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_FORWARDED_FOR'])) {
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	}  
	elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	} 
	return $ip;
}

function fuzzyTradeId($trade_id,$num=3){
	$len=strlen($trade_id);
    return substr($trade_id,0,$num).'*****'.substr($trade_id,-$num);
}

function deep_jm($val,$key=EZKEY){
    return md5(md5($key.$val).$key);
}

function http_pic($pic){
    if(preg_match('|^http://|',$pic)==0){
	    return SITEURL.'/'.$pic;
	}
	else{
	    return $pic;
	}
}

function del_pic($img){
	if($img==''){
		return;
	}
    if(preg_match('|^http://|',$pic)==0){
	    if(file_exists(EZROOT.'/'.$img)){
		    unlink(EZROOT.'/'.$img);
		}
	}
}

function addquote($var)
{
	return str_replace("\\\"", "\"", preg_replace("/\[([a-zA-Z0-9_\-\.\x7f-\xff]+)\]/s", "['\\1']", $var));
}

function RpLine($str)
{
	$str = str_replace("\r","\\r",$str);
	$str = str_replace("\n","\\n",$str);
	return $str;
}



/*时间转换函数*/   
/*function tranTime($time) {       
    $rtime = date("m-d H:i",$time);       
    $htime = date("H:i",$time);       
    $timetime = TIME - $time;       
 
    if ($time < 60) {           
       $str = '刚刚';       
    }       
    else if ($time < 60 * 60) {           
       $min = floor($time/60);           
       $str = $min.'分钟前';       
    }       
    else if ($time < 60 * 60 * 24) {           
       $h = floor($time/(60*60));           
       $str = $h.'小时前 '.$htime;       
    }       
    else if ($time < 60 * 60 * 24 * 3) {           
       $d = floor($time/(60*60*24));           
       if($d==1)              
       $str = '昨天 '.$rtime;           
    else              
       $str = '前天 '.$rtime;       
    }       
    else {           
       $str = $rtime;       
    }       
    return $str;   
}*/

function tranTime($time){
	$str='';
	if(!is_numeric($time)){
		$time=strtotime($time);
	}
	
	$current_time = time();
	if ($time >= $current_time) {
        $time = $time - $current_time;
		if ($time < 60) {
			$str = '马上';
		}
		elseif ($time < 60 * 60) {
			$min = floor($time / 60);
			$str = $min . '分钟后';
		}
		elseif ($time < 60 * 60 * 24) {
			$h = floor($time / (60 * 60));
			$str = $h . '小时后';
		}
		elseif ($time < 60 * 60 * 24 * 30) {
			$d = floor($time / (60 * 60 * 24));
			$str='还有'.$d.'天';
		}
		elseif ($time < 60 * 60 * 24 * 30*12) {
			$d = floor($time / (60 * 60 * 24*30));
			$str='还有'.$d.'个月';
		}
		else{
			$d = floor($time / (60 * 60 * 24*30*12));
			$str='还有'.$d.'年';
		}
	}
	else{
	    $str='已过期'; 
	}
	return $str;
}

function browser() {
	if(!isset($_SERVER["HTTP_USER_AGENT"])){
		return '';
	}
	if (strpos($_SERVER["HTTP_USER_AGENT"], "MSIE")){
		$browser = "ie";
	}
	elseif (strpos($_SERVER["HTTP_USER_AGENT"], "Firefox")){
		$browser = "firefox";
	}
	elseif (strpos($_SERVER["HTTP_USER_AGENT"], "Chrome")){
		$browser = "chrome";
	}
	elseif (strpos($_SERVER["HTTP_USER_AGENT"], "Safari")){
		$browser = "safari";
	}
	elseif (strpos($_SERVER["HTTP_USER_AGENT"], "Opera")){
		$browser = "opera";
	}
	else{
		$browser='';
	}
	return $browser;
}

/*多多函数*/

function alert($word){
    echo script('alert("'.$word.'")');
}

function fenduan($val,$arr=array(),$level=0,$bili=1){
	$re=0;
    foreach($arr as $k=>$v){
        if($level>=$k){
			$re=$val*$v;
			break;
		}
    }
	
	if($re==0){
		$re=$val*$v;
	}
	$re*=$bili;
	return round($re,2);
}

function rep($str){
    $re="/[^\d]/";
    return preg_replace($re,"",$str);
}

function StrCode($string,$key,$action='ENCODE'){
	$key	= substr(md5($_SERVER["HTTP_USER_AGENT"].$key),8,18);
	$string	= $action == 'ENCODE' ? $string : base64_decode($string);
	$len	= strlen($key);
	$code	= '';
	for($i=0; $i<strlen($string); $i++)
	{
		$k		= $i % $len;
		$code  .= $string[$i] ^ $key[$k];
	}
	$code = $action == 'DECODE' ? $code : base64_encode($code);
	return $code;
}

//签名函数
	function createSign ($paramArr) { 
	    global $appSecret; 
	    $sign = $appSecret; 
	    ksort($paramArr); 
	    foreach ($paramArr as $key => $val) { 
	       if ($key !='' && $val !='') { 
	           $sign .= $key.$val; 
	       } 
	    } 
	    $sign = strtoupper(md5($sign.$appSecret));
	    return $sign; 
	}

	//组参函数 
	function createStrParam ($paramArr) { 
	    $strParam = ''; 
	    foreach ($paramArr as $key => $val) { 
	       if ($key != '' && $val !='') { 
	           $strParam .= $key.'='.urlencode($val).'&'; 
	       } 
	    } 
	    return $strParam; 
	}



function param2str($parame) {
	$parame_str = '';
	if (!empty ($parame)) {
		foreach ($parame as $k => $v) {
			if ($k != '') {
				$parame_str .= $k . '=' . urlencode($v) . '&';
			}
		}
		$parame_str = preg_replace('/&$/', '', $parame_str);
	}
	return $parame_str;
}

function filename(){ 
	$dir_file = $_SERVER['SCRIPT_NAME']; 
	$filename = basename($dir_file); 
	return $filename; 
} 

/**
 * 字符串截取，支持中文和其他编码
 *
 * @param string $str 需要转换的字符串
 * @param string $start 开始位置
 * @param string $length 截取长度
 * @param string $charset 编码格式
 * @param string $suffix 截断字符串后缀
 * @return string
 */
function substr_ext($str, $start=0, $length, $charset="utf-8", $suffix="")
{
    if(function_exists("mb_substr")){
         return mb_substr($str, $start, $length, $charset).$suffix;
	}
    elseif(function_exists('iconv_substr')){
         return iconv_substr($str,$start,$length,$charset).$suffix;
    }
    $re['utf-8']  = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
    $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
    $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
    $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
    preg_match_all($re[$charset], $str, $match);
    $slice = join("",array_slice($match[0], $start, $length));
    return $slice.$suffix;
}
function ez_addslashes(&$v,$do=0) {
	if (get_magic_quotes_gpc() == 0 || $do==1) {
		if (is_array($v)) {
			foreach ($v as $key => $value) {
				if (is_array($value)) {
					ez_addslashes($v[$key]);
				} else {
					$value = addslashes(trim($value));
					$v[$key] = $value;
				}
			}
		}
		else {
			$v = addslashes($v);
		}
	}
	return $v;
}

function ez_display_form($r,$v,$displayval=""){
    global $ezhand,$catid,$id,$PowerInfo;
  
    if($PowerInfo<>1){
        $isuser=1;
    }else{
        $isuser=0;
    }
    if($isuser==1 && $r["isadmin"]==2){
        
        return "";
    }
    
    
    $reginfo="";
    $height=0;
    if($r["isrequired"]==1){
        $reginfo='class="required"';
    }
    if($v==""){
            $v=$r["defaultval"];
    }    
    if($r["formtype"]=="text" or $r["formtype"]=="int"){
        if($isuser==1&&$r["isadmin"]==1){
        $fieldinfo=$v;
            
        }else{
        $fieldinfo='<input type="text" name="'.$r["field"].'" style="width:'.$r["inputsize"].'px"  value="'.$v.'" '.$reginfo.' />
        <span class="info">&nbsp;'.$r["tips"].'</span>';
        }
    }elseif($r["formtype"]=="password"){
        if(!empty($id)){
            $reginfo="";
        }
        $fieldinfo='<input type="text" name="'.$r["field"].'" style="width:'.$r["inputsize"].'px"  value="'.$v.'" '.$reginfo.' />
        <span class="info">&nbsp;'.$r["tips"].'</span>';        

    }elseif($r["formtype"]=="datetime"){
        $fieldinfo='<input type="text" name="'.$r["field"].'" class="date textInput readonly"  readonly="true" style="width:'.$r["inputsize"].'px"  value="'.$v.'" '.$reginfo.' />
        <a class="inputDateButton" href="javascript:;">选择</a><span class="info">&nbsp;'.$r["tips"].'</span>';        
     


    }elseif($r["formtype"]=="maps"){
        if($v==""){
            $v="116.404, 39.915";
        }
	    srand(seed());
        $contentid2=time()+mt_rand (0,10240000 ); 
                
        $fieldinfo='
        <div id="map_canvas'.$contentid2.'" style="width:600px; height:400px; "></div>
        <script type="text/javascript">
		var map = new BMap.Map("map_canvas'.$contentid2.'");
		var point = new BMap.Point('.$v.');
		map.centerAndZoom(point, 14);
		map.enableScrollWheelZoom();
		var marker = new BMap.Marker(point);
		map.addOverlay(marker);
		map.addEventListener("click", function(e){
		  document.getElementById("'.$r["field"].''.$contentid2.'").value=e.point.lng + ", " + e.point.lat;
		  var newpoint=new BMap.Point(e.point.lng,e.point.lat);
		  map.clearOverlays(marker);
		 marker = new BMap.Marker(newpoint);
		  map.addOverlay(marker);
		});
        </script>
        <input type="hidden" name="'.$r["field"].'" id="'.$r["field"].''.$contentid2.'" style="width:'.$r["inputsize"].'px"  value="'.$v.'" />   
        ';
     
    }elseif($r["formtype"]=="province"){
     
     if(!empty($v)){
        $ilist=unserialize($v);
     }else{
        $ilist["province"]="";
     }
	    srand(seed());
        $contentid9=time()+mt_rand (0,10240000 );              
       $fieldinfo='<script type="text/javascript" src="js/jsAddress.js"></script> 省：<select id="province'.$contentid9.'" name="province"></select>
市：<select id="city'.$contentid9.'" name="city"></select>
区：<select id="district'.$contentid9.'" name="district"></select>
<script type="text/javascript">
	addressInit("province'.$contentid9.'", "city'.$contentid9.'", "district'.$contentid9.'", "'.$ilist["province"].'", "'.$ilist["city"].'", "'.$ilist["district"].'");
</script>
';
       
     
     }elseif($r["formtype"]=="selectbox"){
        
     $pre=substr($r["field"],0,1);
     $glp=getother($r["field"],$pre,' '.$pre.'_id asc',$v);
        
     $fieldinfo='<select name="'.$r["field"].'" class="txt" id="'.$r["field"].'"><option>请选择</option>'.$glp.'</select><span class="info">&nbsp;'.$r["tips"].'</span>';
    }elseif($r["formtype"]=="box"){
       $pre=substr($r["field"],0,1);
       $order=$pre.'_id asc';
       $arr = $ezhand->select_all($r["field"],"{$pre}_id,{$pre}_name",'1 order by '.$order);
       $fieldinfo="";
       $i=0;
       $ilist=array();
       if(!empty($v)){
          $ilist=unserialize($v);
       }       
       
       while(list($k,$row)=each($arr)){
        if(is_array($ilist)){
        if (in_array($row["{$pre}_id"],$ilist)){
            $ch='checked="checked"';
        }else{
            $ch='';
        }
        }else{
            $ch='';
        }
        
        
        $fieldinfo.='<span class="info"><input type="checkbox" name="'.$r["field"].'[]" value="'.$row[$pre."_id"].'" '.$ch.'  /> '.$row[$pre."_name"].'</span>';                    
               
        $i++;             
        
       }
        
    }elseif($r["formtype"]=="image"){

	    srand(seed());
        $contentid2=time()+mt_rand (0,10240000 ); 
        $fieldinfo='<input name="'.$r["field"].'.id" id="'.$r["field"].'_'.$contentid2.'id" value="" type="hidden" />
        <input type="text" name="'.$r["field"].'.fileName" id="'.$r["field"].'_'.$contentid2.'fileName" class="readonly" style="width: '.$r["inputsize"].'px;" readonly="readonly" value="'.$v.'"  />
        <a class="btnPic" href="'.u("content","upload").'" lookupGroup="'.$r["field"].'" width="460" height="200" title="'.$r["tips"].'">附件</a>
        <span class="info">&nbsp;'.$r["tips"].' <img src="images/cross.png" style="cursor: pointer;" onclick="javascript:clearimginfo(\''.$r["field"].'_'.$contentid2.'\')" ></span>';

        
        //$fieldinfo='<input type="text" name="'.$r["field"].'" style="width:'.$r["inputsize"].'px"  value="'.$v.'" '.$reginfo.' />
        //<span class="info">&nbsp;'.$r["tips"].'</span>';        
    }elseif($r["formtype"]=="number"){
        if($reginfo<>""){
            $reginfo='class="required digits"';
        }else{
            $reginfo='class="digits"';
        }
        $fieldinfo='<input type="text" name="'.$r["field"].'" style="width:'.$r["inputsize"].'px"  value="'.$v.'" '.$reginfo.' />
        <span class="info">&nbsp;'.$r["tips"].'</span>';        
    }elseif($r["formtype"]=="textarea"){
        
          $fieldinfo='<textarea name="'.$r["field"].'" id="'.$r["field"].'" style="width:'.$r["inputsize"].'px" rows="5">'.$v.'</textarea>
        <span class="info">&nbsp;'.$r["tips"].'</span>';   
     }elseif($r["formtype"]=="images"){
     $i=0;
     $ilist=array();
     if(!empty($v)){
        $ilist=unserialize($v);
     }
	srand(seed());
    $contentid2=time()+mt_rand (0,10240000 );     
     while($i<10){
        
        $fieldinfo.='<input name="'.$r["field"].''.$i.'.id" id="'.$r["field"].''.$i.'_'.$contentid2.'id" value="'.$ilist["ids"][$i].'" type="hidden" />
        <input type="text" name="'.$r["field"].''.$i.'.fileName" id="'.$r["field"].''.$i.'_'.$contentid2.'fileName" class="readonly" style="width: 300px;" readonly="readonly" value="'.$ilist["names"][$i].'"  />
        <a class="btnPic" href="'.u("content","upload").'" lookupGroup="'.$r["field"].''.$i.'" width="460" height="200" title="'.$r["tips"].'">附件</a>
        <input name="'.$r["field"].''.$i.'.title" id="'.$r["field"].''.$i.'_'.$contentid2.'title" value="'.$ilist["titles"][$i].'" type="text" />
        
        <span class="info">&nbsp;说明 &nbsp;<img src="images/cross.png" style="cursor: pointer;" onclick="javascript:clearimginfo(\''.$r["field"].''.$i.'_'.$contentid2.'\')" ></span>';                    
               
     $i++;     
     }
     $height=100;  
     }elseif($r["formtype"]=="links"){    
     $i=0;
     $ilist=array();
     if(!empty($v)){
        $ilist=unserialize($v);
     }
     
     while($i<9){
        
        $fieldinfo.='
        <span class="info">标题:</span><input type="text" name="'.$r["field"].''.$i.'.title" style="width: 200px;"  value="'.$ilist["titles"][$i].'"  />
        <span class="info">链接:</span>
        <input name="'.$r["field"].''.$i.'.url" value="'.$ilist["urls"][$i].'" tyle="width: 200px;" type="text" /><br />
        ';                    
               
     $i++;     
     }     
     
     
     $height=100;
    }elseif($r["formtype"]=="attribute"){  
        
     $i=0;
     $ilist=array();

     if(!empty($v)){
        $ilist=unserialize($v);
     }
     
     while($i<15){
        
        $fieldinfo.='
        <span class="info">科目'.($i+1).':</span><input type="text" name="'.$r["field"].''.$i.'.title" style="width: 100px;"  value="'.$ilist["titles"][$i].'"  />
        <span class="info">成绩:</span>
        <input name="'.$r["field"].''.$i.'.val" value="'.$ilist["vals"][$i].'" tyle="width: 300px;" type="text" /><br />
        ';                    
               
     $i++;     
     }     
     
     
     $height=100;
             
        
    }elseif($r["formtype"]=="radio"){
        if(!empty($r["forminfo"])){
            $slist=explode("\n",$r["forminfo"]);
            if(!empty($slist)){
                $i=0;
                while(list($k,$v2)=each($slist)){
                    if($v==$i){
                        $fieldinfo.="<input type='radio' name=\"".$r["field"]."\" id=\"".$r["field"]."\" value='".$i."' checked=\"true\" style=\"width:".$r["inputsize"]."px\" > ".$v2;
                    }else{
                        $fieldinfo.="<input type='radio' name=\"".$r["field"]."\" id=\"".$r["field"]."\" value='".$i."' style=\"width:".$r["inputsize"]."px\" > ".$v2;    
                    }
                    
                    $i++;
                    
                }
                
            }
            
            
        }
        
    }elseif($r["formtype"]=="editor1"){    
	srand(seed());
    $contentid=time()+mt_rand (0,10240000 );    
 
       $fieldinfo='<textarea id="content'.$contentid.'" name="'.$r["field"].'">'.$v.'</textarea>
<script type="text/javascript">
UE.getEditor("content'.$contentid.'");
</script>';
        
    }elseif($r["formtype"]=="editor"){
	srand(seed());
    $contentid=time()+mt_rand (0,10240000 );    
    //if($catid=="75" or $catid=="76"  or $catid=="79"){      
       $fieldinfo='<textarea id="content'.$contentid.'" name="'.$r["field"].'">'.$v.'</textarea>
<script type="text/javascript">
UE.getEditor("content'.$contentid.'");
</script>';
     //}else{   
     //  $fieldinfo=' <textarea class="editor" name="'.$r["field"].'" rows="10" cols="100">'.$v.'</textarea>';
    // }
        
    }elseif($r["formtype"]=="category"){
        
        $fieldinfo='<input name="'.$r["field"].'.id" value="'.$v.'" id="categoryids" type="hidden"><input type="text" name="'.$r["field"].'.orgName" style="width:'.$r["inputsize"].'px"  value="'.$displayval.'" class="lookup" />
        <a class="btnLook" href="'.u("content","catlisttree",array("v"=>"")).'" lookupGroup="'.$r["field"].'">选择同步发布栏目</a>
        <input class="readonly" name="'.$r["field"].'.orgNum" readonly="readonly" type="hidden"/>
        <span class="info">&nbsp;'.$r["tips"].'</span>';        
    }elseif($r["formtype"]=="linkcat"){
       
        if($isuser==1&&$r["isadmin"]==1){
            $fieldinfo=$displayval;
        }else{    
        $fieldinfo='<input name="'.$r["field"].'.id" value="'.$v.'" id="linkcats" type="hidden"><input type="text" name="'.$r["field"].'.orgName" style="width:'.$r["inputsize"].'px"  value="'.$displayval.'" class="lookup" />
        <a class="btnLook" href="'.u("content","linkcat",array("v"=>"","catid"=>$r["defaultval"])).'" lookupGroup="'.$r["field"].'">选择</a>
        <input class="readonly" name="'.$r["field"].'.orgNum" readonly="readonly" type="hidden"/>
        <span class="info">&nbsp;'.$r["tips"].'</span>';          
        }
    
        
    }elseif($r["formtype"]=="linkspecial"){

        $fieldinfo='<input name="'.$r["field"].'.id" value="'.$v.'" id="specialids" type="hidden"><input type="text" name="'.$r["field"].'.orgName" style="width:'.$r["inputsize"].'px"  value="'.$displayval.'" class="lookup" />
        <a class="btnLook" href="'.u("content","speciallist",array("v"=>"")).'" lookupGroup="'.$r["field"].'">选择期刊/专题</a>
        <input class="readonly" name="'.$r["field"].'.orgNum" readonly="readonly" type="hidden"/>
        <span class="info">&nbsp;'.$r["tips"].'</span>';          

    }
    if($height>0){
    $html='<dl>
    <dt>'.$r['name'].'：</dt>
    <dd style="height:'.$height.'">
    '.$fieldinfo.'
    </dd>
    </dl>';        
    }else{
    $html='<dl>
    <dt>'.$r['name'].'：</dt>
    <dd>
    '.$fieldinfo.'
    </dd>
    </dl>';
    }
    
    return $html;
}


function ez_exit($str=''){
    global $ezhand;
	if(isset($ezhand)){$ezhand->close();}
	echo $str;
	unset($ezhand);
	exit;
}

function ob_gzip($content)
{    
    if(!headers_sent() &&  extension_loaded("zlib") && strpos($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")!==false)
    {
        $content = gzencode($content,9);
        header("Content-Encoding: gzip");
        header("Vary: Accept-Encoding");
        header("Content-Length: ".strlen($content));
    }
    return $content;
}

function strtoarray($str){
	$str=str_replace('，',',',$str);
	$str=preg_replace('/[\n\r\t\s]+/i',',',$str);
	$arr=explode(',',$str);
	return $arr;
}

function limit_ip($name,$ip=''){
	if($ip=='')	{
		$ip=get_client_ip();
	}
	$limit_ip=ez_get_cache($name);
	if($limit_ip[0]=='') return 0;
	$ips=implode('|',$limit_ip);
	if(preg_match('/'.$ips.'/',$ip)==1){
		return 1;
	}
	return 0;
}


function no_cache(){
	header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");      
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");      
	header("Cache-Control: no-cache, must-revalidate");      
	header("Pragma: no-cache");
}


function gbk2utf8($string, $encoding = 'utf8') {
	if(GBK_UTF8_FUN==2){
		if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$string) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$string) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$string) == true){
			return $string;
		}
		else{
			return iconv('gb2312','utf-8',$string);
		}
	}
	else{
		$is_utf8 = preg_match('%^(?:[\x09\x0A\x0D\x20-\x7E]| [\xC2-\xDF][\x80-\xBF]|  \xE0[\xA0-\xBF][\x80-\xBF] | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}    |  \xED[\x80-\x9F][\x80-\xBF] |  \xF0[\x90-\xBF][\x80-\xBF]{2}  | [\xF1-\xF3][\x80-\xBF]{3}  |  \xF4[\x80-\x8F][\x80-\xBF]{2} )*$%xs', $string);
		if ($is_utf8 && $encoding == 'utf8') {
			return $string;
		}
		elseif ($is_utf8) {
			return mb_convert_encoding($string, $encoding, "UTF-8");
		} else {
			return mb_convert_encoding($string, $encoding, 'gbk,gb2312,big5');
		}
	}
}

function ez_glob($dir){
	if(!preg_match('/.*\/$/',$dir)){
		$dir.='/';
	}
	$a=array();
	$b=array();
	$a=glob($dir.'*');
	$b=glob($dir.'.*');
	foreach($b as $k=>$v){
		if($v==$dir.'.' || $v==$dir.'..'){
			unset($b[$k]);
		}
	}
	if(empty($a)){
		return $b;
	}
	elseif(empty($b)){
		return $a;
	}
	else{
		return array_merge($a,$b);
	}
}

function get2var(){
	foreach($_GET as $k=>$v){
		global $$k;
		$$k=$v;
	}
}

function post2var($arr=array(),$strict=0){
	$re=1;
	foreach($_POST as $k=>$v){
		if($v==='' && $strict==1){ //严格检测post，不准有空
			$re=0;
			break;
		}
		global $$k;
		$$k=htmlspecialchars($v);
		if(!empty($arr)){
			$arr=array_diff($arr,array($k));
		}

	}
	if(!empty($arr)){  //严格检测post，不准不存在
		if(count($arr)>0){
		    $re=0;
	    }
	}
	return $re;
}

function data_type($v,$type=1){
	if($type==1){
		return (int)$v;
	}
	elseif($type==2){
		return (floor($v*100))/100;
	}
}


function del_magic_quotes_gpc($content){
	if(get_magic_quotes_gpc()==1){
		if(strpos($content,'\\"')!==false){
			$content=str_replace('\\"','"',$content);
		}
		if(strpos($content,"\\'")!==false){
			$content=str_replace("\\'","'",$content);
		}
	}
	return $content;
}

function ez_hash_hmac( $algo , $data , $key , $raw_output = false ){
	if(function_exists('hash_hmac')){
		return hash_hmac($algo, $data, $key, $raw_output);
	}

	$algo = strtolower($algo);
	if($algo == 'sha1'){
		$pack = 'H40';
	}
	elseif($algo == 'md5')
	{
		$pack = 'H32';
	}
	else
	{
		return '';
	}
	$size = 64;
	$opad = str_repeat(chr(0x5C), $size);
	$ipad = str_repeat(chr(0x36), $size);
	if (strlen($key) > $size) {
		$key = str_pad(pack($pack, $algo($key)), $size, chr(0x00));
	} else {
		$key = str_pad($key, $size, chr(0x00));
	}
	for ($i = 0; $i < strlen($key) - 1; $i++) {
		$opad[$i] = $opad[$i] ^ $key[$i];
		$ipad[$i] = $ipad[$i] ^ $key[$i];
	}
	$output = $algo($opad.pack($pack, $algo($ipad.$data)));
	return ($raw_output) ? pack($pack, $output) : $output;
}
function isCrawler($agent="") {
        if(empty($agent)){
        $agent= strtolower($_SERVER['HTTP_USER_AGENT']);
        }  
        if (!empty($agent)) {                 
                $spiderSite= array(
                        "TencentTraveler",
                        "Baiduspider",
                        "BaiduGame",
                        "Googlebot",
                        "msnbot",
                        "Sosospider",
                        "Sogou",
                        "ia_archiver",
                        "Yahoo",
                        "YoudaoBot",
                        "Yahoo Slurp",
                        "MSNBot",
                        "Java (Often spam bot)",
                        "BaiDu",
                        "Voila",
                        "Yandex bot",
                        "BSpider",
                        "twiceler",
                        "Sogou",
                        "Speedy Spider",
                        "Google AdSense",
                        "Heritrix",
                        "Python-urllib",
                        "Alexa",
                        "Ask",
                        "Exabot",
                        "soso",
                        "YodaoBot",
                        "yacy",
                        "SurveyBot",
                        "legs",
                        "lwp-trivial",
                        "Nutch",
                        "StackRambler",
                        "The web archive (IA Archiver)",
                        "Perl tool",
                        "MJ12bot",
                        "Netcraft",
                        "MSIECrawler",
                        "WGet tools",
                        "larbin",
                        "Fish search",
                );   
               foreach($spiderSite as $val) {                        
                        $str = strtolower($val);
                        if (strpos($agent, $str) !== false) {
                                return true;
                        }                        
                }   
        } else {
                return false;
        } 
}


?>